<!DOCTYPE html>
<html lang="en">
<head>
    <title>巡检记录-精工云MES系统移动端</title>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="apple-mobile-web-app-status-bar-style" content="yes">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <link href="/JG/Content/jquery/weui/style/weui.min.css" rel="stylesheet" />
    <link href="/JG/Content/jquery/jquery-weui/css/jquery-weui.min.css" rel="stylesheet" />
    <link href="/JG/Content/css/Global.css" rel="stylesheet" />
    <link rel="stylesheet" href="/JG/Content/css/bootstrap.min.css">
    <link href="/JG/Content/jquery/jquery-weui/css/icon.css" rel="stylesheet" />
    <link rel="stylesheet" href="/JG/Content/css/MobilePollingRecord.css?v=1">

    <script src="/JG/Content/jquery/jquery-3.2.1.min.js"></script>
    <script src="/JG/Content/LocalConfigs.js"></script>
    <script src="/JG/Content/LocalUserInfo.js"></script>
    <script src="/JG/Content/Utils.js?v=1"></script>
</head>
<body>
    <div id="ContentContainer" class="content_container">
        <!--header部分-->
        <header class="header">
            <div class="empty">
                <span id="stations"></span>
            </div>
            <div class="weui-flex">
                <div class="weui-flex__item" style="position:absolute;">
                        <span style="font-size:16px;padding-left: 10px;" class="icon icon-109 f-white" onclick="javascript:location.href='/JG/Quality/MobileMovePolling.html'">
                            返回
                        </span>
                </div>
                <div class="weui-flex__item" style="text-align: center;">巡检记录</div>
                <div class="weui-flex__item" style="position:absolute;right:10px;">
                    <span><img src="/JG/Content/images/save.png" alt="" style="width:30px;height: 30px"v-on:click="SavePollingData"></span>
                </div>
            </div>
        </header>

        <!--解决浮动空内容div-->
        <div class="empty_div"></div>

        <!--主体部分-->
        <div id="MainPage" v-cloak>
            <div class="polling">
                <div class="polling_top">
                    <ul class="list-group">
                        <li class="list-group-item">
                            <div>
                                产线名称：
                                <select class="form-control" v-model="FormData.NowProductionLineCode" v-on:change="ChooseProductionLine">
                                    <option v-for="(item,index) in ProLineData" v-bind:value="item.CXSJ_CXBM">{{item.CXSJ_CXMC}}</option>
                                </select>
                            </div>
                        </li>
                        <li class="list-group-item">
                            任务单号：
                            <div>
                                <select class="form-control" v-model="FormData.TaskOrder" v-on:change="ChooseTaskCode">
                                    <option v-for="(item,index) in TaskOrderData" v-bind:value="item.SCRW_RWDH">{{item.SCRW_RWDH}} </option>
                                </select>
                            </div>
                        </li>
                        <li class="list-group-item">
                            标准方案：
                            <div>
                                <select id="XjFa" class="form-control" v-model="FormData.PollingSchemeID" v-on:change="CheckoutClassify">
                                    <option v-for="(item,index) in PollingSchemeData" value="item.JGMES_ZLGL_CPJYBZ_ID"  v-bind:value="item.JGMES_ZLGL_CPJYBZ_ID">{{item.CPJYBZ_BZMC}}</option>
                                </select>
                            </div>
                        </li>
                        <li class="list-group-item">
<!--                            <div class="pull-right">-->
<!--                            <div>-->
<!--                                <span>巡检时间：{{FormData.PollingTime}}</span>-->
<!--                            </div>-->
                            <div>
                                <span>客户名称：{{FormData.ClientName}}</span>
                            </div>
<!--                            <div class="client_name">-->
                            <div>
                                <span>产品编码：{{FormData.MaterialCode}}</span>
                            </div>
                            <div>
                                <span>产品名称：{{FormData.MaterialName}}</span>
                            </div>
                        </li>
                    </ul>
                </div>

                <!--树形结构部分-->
                <div id="localTree">
                    <div id="tree_structure" class="tree_structure"></div>
                </div>

            </div>
        </div>
    </div>
</body>
<script src="/JG/Content/jquery/jquery-weui/js/jquery-weui.min.js"></script>
<script src="/JG/Content/bootstrap.min.js"></script>
<script src="/JG/Content/vue-v2.34.js"></script>
<script src="/JG/Content/Common.js"></script>
<script src="/JG/Content/PollingDown2.js"></script>
<script type="text/javascript">
    var vmPage = new Vue({
        el:"#ContentContainer",
        data:{
            FormData:{
                NowProductionLineCode:"",    //默认产线编码
                TaskOrder:"",     //任务单号
                ProdLine:"",    //产线名称
                InvCode:"",      //产品编号
                PollingSchemeName:"",    //巡检方案名称
                PollingSchemeID:"",     //巡检方案ID
                PollingClassifyID:"",     //巡检分类项ID
               // MajorID:"",         //巡检主键ID
                ClientName:"",    //客户名称
                PollingTime:"",     //巡检时间
                MaterialCode: "",  //物料编码
                MaterialName: "",  //物料名称
                ClientCode:"",      //客户编码
                TaskOrderState:"",  //生产任务状态
            },
            ProLineData:[],      //产线集合
            TaskOrderData:[],    //任务单信息
            PollingSchemeData:[],    //巡检方案集合
            PollingListData:[],     //巡检项目明细集合
        },
        mounted:function(){
            var currSelf = this;
            currSelf.initData();    //初始化方法
        },
        methods:{
            //初始化方法
            initData: function () {
                var currSelf = this;
                //获取产线接口
                $.showLoading();
                $.ajax({
                    type: "post",
                    url: LocalConfig.SrvPath + "/jgmes/jgmesBaseAction!getCxList.action",
                    data: {},
                    dataType: "json",
                    success: function (result) {
                        var retData = ReturnData(result);
                        //console.log(retData);
                        if (retData.IsSuccess) {
                            if (retData.Data.length>0) {
                                currSelf.ProLineData = retData.Data;
                                currSelf.FormData.NowProductionLineCode = LocalUserInfo.GetUserInfo().ProductionLineCode;   //把用户登陆时绑定的产线编码赋值
                                //初始化任务单信息
                                if(currSelf.FormData.NowProductionLineCode.length > 0){
                                    //任务单号接口
                                    $.ajax({
                                        type: "post",
                                        url: LocalConfig.SrvPath + "/jgmes/commonAction!getScrw.action",
                                        data: {
                                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                            "mac": LocalUserInfo.GetUserInfo().Mac,
                                            "cxCode": currSelf.FormData.NowProductionLineCode,      //当的产线
                                            "curDate": currSelf.curDate,
                                            "zt":"RWZT01,"+"RWZT02,"+"RWZT03,"+"RWZT04,"+"RWZT05"
                                        },
                                        dataType: "json",
                                        success: function (result) {
                                            var ret = ReturnData(result);
                                            if (ret.IsSuccess) {
                                                console.log("生产任务单")
                                                console.log(ret)
                                                if (ret.Data.length>0) {
                                                    currSelf.TaskOrderData = ret.Data;
                                                    currSelf.FormData.TaskOrder = ret.Data[0].SCRW_RWDH;    //默认任务单号
                                                    currSelf.FormData.InvCode = ret.Data[0].SCRW_CPBH;    //默认第一个产品编号
                                                    currSelf.FormData.ClientName = ret.Data[0].SCRW_KHMC;    //客户名称
                                                    currSelf.FormData.PollingTime = ret.Data[0].SCRW_SJKGSJ;    //巡检时间
                                                    currSelf.FormData.MaterialCode = ret.Data[0].SCRW_CPBH;    //物料编号
                                                    currSelf.FormData.MaterialName = ret.Data[0].SCRW_NAME;    //物料名称
                                                    currSelf.FormData.NowProductionLineCode = ret.Data[0].SCRW_CXBM;//产线编码
                                                    currSelf.FormData.ProdLine = ret.Data[0].SCRW_CXMC;//产线名称
                                                    currSelf.FormData.ClientCode = ret.Data[0].SCRW_KHBM;//客户编码

                                                    //初始化巡检方案信息
                                                    if(currSelf.FormData.InvCode){
                                                        //根据产品获取巡检方案列表接口
                                                        $.ajax({
                                                            type: "post",
                                                            url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandard.action",
                                                            data: {
                                                                "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                                "mac": LocalUserInfo.GetUserInfo().Mac,
                                                                // "cpbm": currSelf.FormData.InvCode,      //产品编码
                                                                "jylx":"XJ",     //检验类型(固定值)
                                                            },
                                                            dataType: "json",
                                                            success: function (ret) {
                                                                var retData = ReturnData(ret);
                                                                console.log(retData);
                                                                if (retData.IsSuccess && retData.Data.length>0) {
                                                                    currSelf.PollingSchemeData = retData.Data;
                                                                    currSelf.FormData.PollingSchemeName = retData.Data[0].CPJYBZ_BZMC;    //默认第一个巡检方案名称
                                                                    currSelf.FormData.PollingSchemeID = retData.Data[0].JGMES_ZLGL_CPJYBZ_ID;    //获取默认第一个巡检方案ID
                                                                    currSelf.CheckoutClassify();
                                                                    // //根据巡检方案ID请求对应的巡检分类项
                                                                    // if(currSelf.FormData.PollingSchemeID){
                                                                    //     //获取检验分类项接口
                                                                    //     $.showLoading();
                                                                    //     $.ajax({
                                                                    //         type: "post",
                                                                    //         async:false,
                                                                    //         url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getInspectionItemRootClassify.action",
                                                                    //         data: {
                                                                    //             "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                                    //             "mac": LocalUserInfo.GetUserInfo().Mac,
                                                                    //             "jybzID":currSelf.FormData.PollingSchemeID,   //巡检检验方案ID
                                                                    //         },
                                                                    //         dataType: "json",
                                                                    //         success:function(result){
                                                                    //             var res = ReturnData(result);
                                                                    //             console.log(res);
                                                                    //             if(res.IsSuccess){
                                                                    //                 if(res.Data){
                                                                    //                     tree.str="";
                                                                    //                     //currSelf.FirstCheckoutData = res.Data;
                                                                    //                     // currSelf.FormData.PollingClassifyID = res.Data[0].JGMES_ZLGL_JCXMFL_ID;
                                                                    //                     var strHtml="";
                                                                    //                     for (var k = 0;k<res.Data.length;k++){
                                                                    //                         currSelf.FormData.PollingClassifyID = res.Data[k].JGMES_ZLGL_JCXMFL_ID;
                                                                    //                         //根据巡检方案ID和巡检项目分类ID请求对应的巡检项目明细
                                                                    //                         if(currSelf.FormData.PollingClassifyID){
                                                                    //                             //获取字表信息接口
                                                                    //                             $.showLoading();
                                                                    //                             $.ajax({
                                                                    //                                 type: "post",
                                                                    //                                 url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandardChild.action",
                                                                    //                                 data: {
                                                                    //                                     "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                                    //                                     "mac": LocalUserInfo.GetUserInfo().Mac,
                                                                    //                                     "jybzID":currSelf.FormData.PollingSchemeID,    //巡检主键ID
                                                                    //                                     "rootId":currSelf.FormData.PollingClassifyID,    //检验分类项ID
                                                                    //                                 },
                                                                    //                                 dataType: "json",
                                                                    //                                 success:function(result){
                                                                    //                                     var res = ReturnData(result);
                                                                    //                                     console.log(res);
                                                                    //                                     if(res.IsSuccess){
                                                                    //                                         if(res.Data.length>0){
                                                                    //                                             console.log("tree")
                                                                    //                                             console.log(res.Data)
                                                                    //                                             //currSelf.PollingListData = res.Data;
                                                                    //                                             //添加无级树
                                                                    //                                             tree.str="";
                                                                    //                                             var str=tree.forTree(res.Data);
                                                                    //                                             $(".tree_structure").html(str);
                                                                    //                                         }else {
                                                                    //                                             var showMsg = "没有相关的检验项目信息!";
                                                                    //                                             $.toptip(showMsg, "warning");
                                                                    //                                         }
                                                                    //                                     }else {
                                                                    //                                         $.toptip(res.message, "error");
                                                                    //                                     }
                                                                    //                                 },
                                                                    //                                 error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                                    //                                     $.alert("请求失败" + errorThrown);
                                                                    //                                 },
                                                                    //                                 complete: function () {
                                                                    //                                     //当数据加载完成隐藏加载弹窗
                                                                    //                                     $.hideLoading();
                                                                    //                                 }
                                                                    //                             });
                                                                    //                         }
                                                                    //                     }
                                                                    //                 }else {
                                                                    //                     var showMsg = "没有相关的检验信息!";
                                                                    //                     $.toptip(showMsg, "warning");
                                                                    //                 }
                                                                    //             }else {
                                                                    //                 $.toptip(res.message, "error");
                                                                    //             }
                                                                    //         },
                                                                    //         error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                                    //             $.alert("请求失败" + errorThrown);
                                                                    //         },
                                                                    //         complete: function () {
                                                                    //             //当数据加载完成隐藏加载弹窗
                                                                    //             $.hideLoading();
                                                                    //         }
                                                                    //     });
                                                                    // }

                                                                } else if (!retData.Data){
                                                                    var showMsg = "此任务单没有绑定相关的检验方案!";
                                                                    $.toptip(showMsg, "warning");
                                                                }
                                                            },
                                                            error: function (xhr, status, errorThrown) {
                                                                console.error(errorThrown);
                                                            }
                                                        });
                                                    }
                                                }
                                                // else{
                                                    // var showMsg = "当前产线信息为空!";
                                                    // $.toptip(showMsg, "warning");
                                                // }
                                            }else if(!ret.Data){
                                                var showMsg = "该生产产线没有任务单号相关信息!";
                                                $.toptip(showMsg, "warning");
                                            }
                                        },
                                        error: function (xhr, status, errorThrown) {
                                            console.error(errorThrown);
                                        }
                                    });
                                }
                            }
                        }else if(!retData.Data){
                            var showMsg = "未能找到产线信息";
                            $.toptip(showMsg, "warning");
                        }
                    },
                    error: function (xhr, status, errorThrow) {
                        console.error(errorThrow);
                    },
                    complete: function () {
                        $.hideLoading();
                    },
                });
            },

            //选择不同产线获取对应任务单方法
            ChooseProductionLine:function(){
                var currSelf = this;
                currSelf.TaskOrderData = [];    //清空之前任务单数据
                currSelf.PollingSchemeData = [];     //清除之前检验方案
                currSelf.PollingListData = [];
                currSelf.FormData.PollingTime = "";
                currSelf.FormData.ClientName = "";
                currSelf.FormData.MaterialCode= "";
                currSelf.FormData.MaterialName= "";
                currSelf.FormData.TaskOrder = "";
                $(".tree_structure").empty();
                $.each(currSelf.ProLineData, function (index, item) {
                    if (currSelf.FormData.NowProductionLineCode == item.CXSJ_CXBM) {
                        currSelf.FormData.NowProductionLineCode = item.CXSJ_CXBM;      //当前产线编码
                        currSelf.FormData.ProdLine = item.CXSJ_CXMC;
                    }
                });

                //初始化任务单信息
                if(currSelf.FormData.NowProductionLineCode){
                    //任务单号接口
                    $.ajax({
                        type: "post",
                        url: LocalConfig.SrvPath + "/jgmes/commonAction!getScrw.action",
                        data: {
                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                            "mac": LocalUserInfo.GetUserInfo().Mac,
                            "cxCode": currSelf.FormData.NowProductionLineCode,      //当的产线
                            "curDate": currSelf.curDate,
                            "zt":"RWZT01,"+"RWZT02,"+"RWZT03,"+"RWZT04,"+"RWZT05"


                        },
                        dataType: "json",
                        success: function (result) {
                            var ret = ReturnData(result);
                            //console.log(ret);
                            if (ret.IsSuccess) {
                                if(ret.Data.length>0){
                                    currSelf.TaskOrderData = ret.Data;
                                    currSelf.FormData.TaskOrder = ret.Data[0].SCRW_RWDH;    //默认任务单号
                                    currSelf.FormData.InvCode = ret.Data[0].SCRW_CPBH;    //默认第一个产品编号
                                    currSelf.FormData.ClientName = ret.Data[0].SCRW_KHMC;    //客户名称
                                    currSelf.FormData.PollingTime = ret.Data[0].SCRW_SJKGSJ;    //巡检时间
                                    currSelf.FormData.MaterialCode = ret.Data[0].SCRW_CPBH;    //物料编号
                                    currSelf.FormData.MaterialName = ret.Data[0].SCRW_NAME;    //物料名称
                                    currSelf.FormData.NowProductionLineCode = ret.Data[0].SCRW_CXBM;//产线编码
                                    currSelf.FormData.ProdLine = ret.Data[0].SCRW_CXMC;//产线名称
                                    currSelf.FormData.ClientCode = ret.Data[0].SCRW_KHBM;//客户编码
                                    $(".tree_structure").empty();

                                    //初始化巡检方案信息
                                    if(currSelf.FormData.InvCode){
                                        //根据产品获取巡检方案列表接口
                                        $.ajax({
                                            type: "post",
                                            url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandard.action",
                                            data: {
                                                "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                "mac": LocalUserInfo.GetUserInfo().Mac,
                                                // "cpbm": currSelf.FormData.InvCode,      //产品编码
                                                "jylx":"XJ",     //检验类型(固定值)
                                            },
                                            dataType: "json",
                                            success: function (ret) {
                                                var retData = ReturnData(ret);
                                                //console.log(retData);
                                                if (retData.IsSuccess && retData.Data) {
                                                    currSelf.PollingSchemeData = retData.Data;
                                                    currSelf.FormData.PollingSchemeName = retData.Data[0].CPJYBZ_BZMC;    //默认第一个巡检方案名称
                                                    currSelf.FormData.PollingSchemeID = retData.Data[0].JGMES_ZLGL_CPJYBZ_ID;    //获取默认第一个巡检方案ID


                                                    //根据巡检方案ID请求对应的巡检分类项
                                                    if(currSelf.FormData.PollingSchemeID){
                                                        //获取检验分类项接口
                                                        $.showLoading();
                                                        $.ajax({
                                                            type: "post",
                                                            async:false,
                                                            url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getInspectionItemRootClassify.action",
                                                            data: {
                                                                "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                                "mac": LocalUserInfo.GetUserInfo().Mac,
                                                                "jybzID":currSelf.FormData.PollingSchemeID,   //巡检检验方案ID
                                                            },
                                                            dataType: "json",
                                                            success:function(result){
                                                                var res = ReturnData(result);
                                                                console.log(res);
                                                                if(res.IsSuccess){
                                                                    tree.str="";
                                                                    if(res.Data){
                                                                        //currSelf.FirstCheckoutData = res.Data;
                                                                        // currSelf.FormData.PollingClassifyID = res.Data[0].JGMES_ZLGL_JCXMFL_ID;
                                                                        for (var k = 0;k<res.Data.length;k++){
                                                                            currSelf.FormData.PollingClassifyID = res.Data[k].JGMES_ZLGL_JCXMFL_ID;
                                                                            //根据巡检方案ID和巡检项目分类ID请求对应的巡检项目明细
                                                                            if(currSelf.FormData.PollingClassifyID){
                                                                                //获取字表信息接口
                                                                                $.showLoading();
                                                                                $.ajax({
                                                                                    type: "post",
                                                                                    url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandardChild.action",
                                                                                    data: {
                                                                                        "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                                                        "mac": LocalUserInfo.GetUserInfo().Mac,
                                                                                        "jybzID":currSelf.FormData.PollingSchemeID,    //巡检主键ID
                                                                                        "rootId":currSelf.FormData.PollingClassifyID,    //检验分类项ID
                                                                                    },
                                                                                    dataType: "json",
                                                                                    success:function(result){
                                                                                        var res = ReturnData(result);
                                                                                        console.log(res);
                                                                                        if(res.IsSuccess){
                                                                                            if(res.Data){
                                                                                                currSelf.PollingListData = res.Data;
                                                                                                //添加无级树
                                                                                                var str=tree.forTree(res.Data);
                                                                                                $(".tree_structure").html(str);
                                                                                            }else {
                                                                                                var showMsg = "没有相关的检验项目信息!";
                                                                                                $.toptip(showMsg, "warning");
                                                                                            }
                                                                                        }else {
                                                                                            $.toptip(res.message, "error");
                                                                                        }
                                                                                    },
                                                                                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                                                        $.alert("请求失败" + errorThrown);
                                                                                    },
                                                                                    complete: function () {
                                                                                        //当数据加载完成隐藏加载弹窗
                                                                                        $.hideLoading();
                                                                                    }
                                                                                });
                                                                            }
                                                                        }

                                                                    }else {
                                                                        var showMsg = "没有相关的首检信息!可点击添加";
                                                                        $.toptip(showMsg, "warning");
                                                                    }
                                                                }else {
                                                                    $.toptip(res.message, "error");
                                                                }
                                                            },
                                                            error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                                $.alert("请求失败" + errorThrown);
                                                            },
                                                            complete: function () {
                                                                //当数据加载完成隐藏加载弹窗
                                                                $.hideLoading();
                                                            }
                                                        });
                                                    }

                                                } else if (!retData.Data){
                                                    var showMsg = "此任务单没有绑定相关的巡检方案!";
                                                    $.toptip(showMsg, "warning");
                                                }
                                            },
                                            error: function (xhr, status, errorThrown) {
                                                console.error(errorThrown);
                                            }
                                        });
                                    }
                                }else{
                                    var showMsg = "该生产产线没有任务单号相关信息!";
                                    $.toptip(showMsg, "warning");
                                }
                            }
                        },
                        error: function (xhr, status, errorThrown) {
                            console.error(errorThrown);
                        }
                    });
                }
            },

            //选择不同任务单获取对应的巡检方案
            ChooseTaskCode:function(){
                var currSelf = this;
                currSelf.PollingSchemeData = [];     //清除之前检验方案
                currSelf.PollingListData = [];
                currSelf.FormData.PollingTime = "";
                currSelf.FormData.ClientName = "";
                currSelf.FormData.MaterialCode= "";
                currSelf.FormData.MaterialName= "";

                tree.str="";
                $.each(currSelf.TaskOrderData, function (i, val) {
                    if (currSelf.FormData.TaskOrder == val.SCRW_RWDH) {
                        currSelf.FormData.TaskOrder = val.SCRW_RWDH;      //当前任务单号
                        currSelf.FormData.InvCode = val.SCRW_CPBH;    //当前产品编码
                        currSelf.FormData.ClientName = val.SCRW_KHMC;    //客户名称
                        currSelf.FormData.PollingTime = val.SCRW_SJKGSJ;    //巡检时间
                        currSelf.FormData.MaterialCode = val.SCRW_CPBH;    //物料编号
                        currSelf.FormData.MaterialName = val.SCRW_NAME;    //物料名称
                        currSelf.FormData.NowProductionLineCode = val.SCRW_CXBM;//产线编码
                        currSelf.FormData.ProdLine = val.SCRW_CXMC;//产线名称
                        currSelf.FormData.ClientCode = val.SCRW_KHBM;//客户编码
                    }
                });
                //初始化巡检方案信息
                if(currSelf.FormData.InvCode){
                    //根据产品获取巡检方案列表接口
                    $.ajax({
                        type: "post",
                        url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandard.action",
                        data: {
                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                            "mac": LocalUserInfo.GetUserInfo().Mac,
                            // "cpbm": currSelf.FormData.InvCode,      //产品编码
                            "jylx":"XJ",     //检验类型(固定值)
                        },
                        dataType: "json",
                        success: function (ret) {
                            var retData = ReturnData(ret);
                            //console.log(retData);
                            if (retData.IsSuccess && retData.Data) {
                                currSelf.PollingSchemeData = retData.Data;
                                currSelf.FormData.PollingSchemeName = retData.Data[0].CPJYBZ_BZMC;    //默认第一个巡检方案名称
                                currSelf.FormData.PollingSchemeID = retData.Data[0].JGMES_ZLGL_CPJYBZ_ID;    //获取默认第一个巡检方案ID
                                //根据巡检方案ID请求对应的巡检分类项
                                if(currSelf.FormData.PollingSchemeID){
                                    //获取检验分类项接口
                                    $.showLoading();
                                    $.ajax({
                                        type: "post",
                                        async:false,
                                        url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getInspectionItemRootClassify.action",
                                        data: {
                                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                            "mac": LocalUserInfo.GetUserInfo().Mac,
                                            "jybzID":currSelf.FormData.PollingSchemeID,   //巡检检验方案ID
                                        },
                                        dataType: "json",
                                        success:function(result){
                                            var res = ReturnData(result);
                                            console.log(res);
                                            if(res.IsSuccess){
                                                if(res.Data){
                                                    //currSelf.FirstCheckoutData = res.Data;
                                                    // currSelf.FormData.PollingClassifyID = res.Data[0].JGMES_ZLGL_JCXMFL_ID;//ljs
                                                    tree.str="";
                                                    for (var k = 0;k<res.Data.length;k++){
                                                        currSelf.FormData.PollingClassifyID = res.Data[k].JGMES_ZLGL_JCXMFL_ID;
                                                        //根据巡检方案ID和巡检项目分类ID请求对应的巡检项目明细
                                                        if(currSelf.FormData.PollingClassifyID){
                                                            //获取字表信息接口
                                                            $.showLoading();
                                                            $.ajax({
                                                                type: "post",
                                                                url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandardChild.action",
                                                                data: {
                                                                    "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                                    "mac": LocalUserInfo.GetUserInfo().Mac,
                                                                    "jybzID":currSelf.FormData.PollingSchemeID,    //巡检主键ID
                                                                    "rootId":currSelf.FormData.PollingClassifyID,    //检验分类项ID
                                                                },
                                                                dataType: "json",
                                                                success:function(result){
                                                                    var res = ReturnData(result);
                                                                    console.log(res);
                                                                    if(res.IsSuccess){
                                                                        if(res.Data){
                                                                            currSelf.PollingListData = res.Data;
                                                                            //添加无级树
                                                                            $(".tree_structure").empty();
                                                                            // $(".tree_structure").append(forTree(res.Data,""));
                                                                            var str=tree.forTree(res.Data);
                                                                            $(".tree_structure").html(str);
                                                                        }else {
                                                                            var showMsg = "没有相关的检验项目信息!";
                                                                            $.toptip(showMsg, "warning");
                                                                        }
                                                                    }else {
                                                                        $.toptip(res.message, "error");
                                                                    }
                                                                },
                                                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                                    $.alert("请求失败" + errorThrown);
                                                                },
                                                                complete: function () {
                                                                    //当数据加载完成隐藏加载弹窗
                                                                    $.hideLoading();
                                                                }
                                                            });
                                                        }
                                                    }

                                                }else {
                                                    var showMsg = "没有相关的首检信息!可点击添加";
                                                    $.toptip(showMsg, "warning");
                                                }
                                            }else {
                                                $.toptip(res.message, "error");
                                            }
                                        },
                                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                                            $.alert("请求失败" + errorThrown);
                                        },
                                        complete: function () {
                                            //当数据加载完成隐藏加载弹窗
                                            $.hideLoading();
                                        }
                                    });
                                }

                            } else if (!retData.Data){
                                var showMsg = "此任务单没有绑定相关的巡检方案!";
                                $.toptip(showMsg, "warning");
                            }
                        },
                        error: function (xhr, status, errorThrown) {
                            console.error(errorThrown);
                        }
                    });
                }
            },
            //保存
            SavePollingData:function(){
                var currSelf = this;
                if (currSelf.FormData.NowProductionLineCode == "undefined" || currSelf.FormData.NowProductionLineCode == null || currSelf.FormData.NowProductionLineCode == ""){
                    $.toptip("产线信息不能为空", "warning");
                    return false;
                }
                if (currSelf.FormData.TaskOrder == "undefined" || currSelf.FormData.TaskOrder == null || currSelf.FormData.TaskOrder == ""){
                    $.toptip("任务单号不能为空", "warning");
                    return false;
                }
                if (currSelf.FormData.PollingSchemeID == "undefined" || currSelf.FormData.PollingSchemeID == null || currSelf.FormData.PollingSchemeID == ""){
                    $.toptip("巡检方案信息不能为空", "warning");
                    return false;
                }


                var jsonStr = {
                    "XJZB_XJSJ":currSelf.FormData.PollingTime,
                    "XJZB_XJBZMC":currSelf.FormData.PollingSchemeName,
                    "XJZB_CXBM":currSelf.FormData.NowProductionLineCode,
                    "XJZB_RWDH":currSelf.FormData.TaskOrder,
                    "XJZB_CPBM":currSelf.FormData.MaterialCode,
                    "XJZB_CPMC":currSelf.FormData.MaterialName,
                    "XJZB_KHBM":currSelf.FormData.ClientCode,
                    "XJZB_KHMC":currSelf.FormData.ClientName,
                    "XJZB_XJR":LocalUserInfo.GetUserInfo().UserCode,
                    "XJZB_CXMC":currSelf.FormData.ProdLine,
                    "XJZB_XJBZZJID":currSelf.FormData.PollingSchemeID,
                };
                var jsonStrDetail = [];
                var radios = $("input[type=radio]:checked");
                console.log("radio");
                console.log(radios);
                for (var k = 0;k<radios.length;k++){
                    var item=$.parseJSON(radios[k].id);
                    var value = radios[k].value;
                    console.log("data+value");
                    console.log(item);
                    console.log(value);
                    jsonStrDetail.push({
                        "XJZBZB_JYXMBM": item.CPJYBZZB_JYXMBM,
                        "XJZBZB_JYXMMC": item.JYXMDA_XMMC,
                        "XJZBZB_NO_CODE":value,
                        "XJZBZB_JYYQ":item.CPJYBZZB_JYYQ,
                    })
                }
                $.ajax({
                    type: "post",
                    url: LocalConfig.SrvPath + "/jgmes/jgmesXunJianAction!dopatrolSave.action",
                    data: {
                        "jsonStr": JSON.stringify(jsonStr),
                        "jsonStrDetail":JSON.stringify(jsonStrDetail),
                    },
                    dataType: "json",
                        success:function(result){
                            var res = ReturnData(result);
                            console.log(res);
                            $.toptip("保存成功", "success");
                            window.location.href = "/JG/Quality/MobileMovePolling.html";
                        },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        $.alert("请求失败" + errorThrown);
                    },
                    complete: function () {
                        //当数据加载完成隐藏加载弹窗
                        $.hideLoading();
                    }
                });
            },

            //选择不同巡检方案获取相应的检验项明细
            CheckoutClassify:function(){
                var currSelf = this;
                $.each(currSelf.PollingSchemeData, function (index, item) {
                    if (currSelf.FormData.PollingSchemeID == item.JGMES_ZLGL_CPJYBZ_ID) {
                        currSelf.FormData.PollingSchemeName=item.CPJYBZ_BZMC;
                    }
                });

                //根据巡检方案ID请求对应的巡检分类项
                if(currSelf.FormData.PollingSchemeName){
                    //获取检验分类项接口
                    $.showLoading();
                    $.ajax({
                        type: "post",
                        async:false,
                        url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getInspectionItemRootClassify.action",
                        data: {
                            "userCode": LocalUserInfo.GetUserInfo().UserCode,
                            "mac": LocalUserInfo.GetUserInfo().Mac,
                            "jybzID":currSelf.FormData.PollingSchemeID,   //巡检检验方案ID
                        },
                        dataType: "json",
                        success:function(result){
                            var res = ReturnData(result);
                            // currSelf.FormData.PollingSchemeName
                            console.log(res);
                            if(res.IsSuccess){
                                if(res.Data){
                                    //currSelf.FirstCheckoutData = res.Data;
                                    // currSelf.FormData.PollingClassifyID = res.Data[0].JGMES_ZLGL_JCXMFL_ID;
                                    $("#localTree").append("");
                                    $("#localTree").html("<div id='tree_structure' class='tree_structure'></div>")
                                    tree.str="";
                                    for (var k = 0;k<res.Data.length;k++){
                                        currSelf.FormData.PollingClassifyID = res.Data[k].JGMES_ZLGL_JCXMFL_ID;
                                        //根据巡检方案ID和巡检项目分类ID请求对应的巡检项目明细
                                        if(currSelf.FormData.PollingClassifyID){
                                            //获取字表信息接口
                                            $.showLoading();
                                            $.ajax({
                                                type: "post",
                                                async:false,
                                                url: LocalConfig.SrvPath + "/jgmes/jgmesFirstInspectionAction!getEffectiveProductStandardChild.action",
                                                data: {
                                                    "userCode": LocalUserInfo.GetUserInfo().UserCode,
                                                    "mac": LocalUserInfo.GetUserInfo().Mac,
                                                    "jybzID":currSelf.FormData.PollingSchemeID,    //巡检主键ID
                                                    "rootId":currSelf.FormData.PollingClassifyID,    //检验分类项ID
                                                },
                                                dataType: "json",
                                                success:function(result){
                                                    var res = ReturnData(result);
                                                    console.log(res);
                                                    if(res.IsSuccess){
                                                        if(res.Data){
                                                            //currSelf.PollingListData = res.Data;
                                                            //添加无级树
                                                            var str=tree.forTree(res.Data);
                                                            $(".tree_structure").html(str);

                                                        }else {
                                                            var showMsg = "没有相关的检验项目信息!";
                                                            console.log(tree.str)
                                                            $(".tree_structure").empty();
                                                            $.toptip(showMsg, "warning");
                                                        }
                                                    }else {
                                                        $.toptip(res.message, "error");
                                                    }
                                                },
                                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                                    $.alert("请求失败" + errorThrown);
                                                },
                                                complete: function () {
                                                    //当数据加载完成隐藏加载弹窗
                                                    $.hideLoading();
                                                }
                                            });
                                        }
                                    }

                                }else {
                                    var showMsg = "没有相关的首检信息!可点击添加";
                                    $(".tree_structure").empty();
                                    $.toptip(showMsg, "warning");
                                }
                            }else {
                                $.toptip(res.message, "error");
                            }
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            $.alert("请求失败" + errorThrown);
                        },
                        complete: function () {
                            //当数据加载完成隐藏加载弹窗
                            $.hideLoading();
                        }
                    });
                }

            },

        },
    });
</script>
</html>